from numpy import ndarray, dtype, floating, float_
from numpy._typing import _64Bit

from factor.BaseFactor import ArrayManagerFactorBase
import talib
import numpy as np
from typing import Union, Literal, Any
from module.dynamic_module.machine_learning.engine import MLEngine


class ArrayManagerFactor(ArrayManagerFactorBase):
    def __init__(self, size, symbol, interval):
        super().__init__(size=size, symbol=symbol, interval=interval)
        # 在因子分析阶段所用到的公共因子（BaseFactor.py内的）
        self.public_factor_ls = ["rsi"]
        # 在因子分析阶段所用到的模型私有因子（BaseFactor.py内的），为空则展示所有私有因子
        self.private_factor_ls = ["sma7"]
        # # 加载机器学习模型到ml engine
        # self.ml_engine = MLEngine()
        # folder_name = ""
        # self.ml_engine.load_model(folder_name)

    def sma7(self, n: int = 7, array: bool = False) -> Union[float, np.ndarray]:
        """
        Simple moving average.
        """
        result: np.ndarray = talib.SMA(self.close, n)
        result = np.round(result, decimals=4)
        if array:
            return result
        return result[-1]

